#include "mutex.h"
#include <iostream>

// Extends and object to be shared between threads.
MutuallyExclusive::MutuallyExclusive()
{
	this->mutex = CreateMutex(NULL, FALSE, NULL);

	return;
}

// Release the property for use on other threads.
bool MutuallyExclusive::release()
{
	return (ReleaseMutex(this->mutex) ? true : false);
}

// Wait until the property is available
DWORD MutuallyExclusive::wait(DWORD timeout)
{
	return WaitForSingleObject(this->mutex, timeout);
}

// Remove the property from being a shared resources.
MutuallyExclusive::~MutuallyExclusive()
{
	CloseHandle(this->mutex);
	delete this->mutex;
}